package com.fengchao.api.controller.v1;

import com.alibaba.fastjson.JSON;
import com.fengchao.api.service.OdrService;
import com.fengchao.api.service.UsrService;
import com.fengchao.model.entity.comm.*;
import com.fengchao.model.odr.OdrOrder;
import com.fengchao.model.odr.OdrOrderItems;
import com.fengchao.util.common.CommonValidator;
import com.fengchao.util.common.DateUtil;
import com.fengchao.util.net.IpUtil;
import com.fengchao.util.wechat.pay.WeixinPay;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;

import static com.fengchao.api.config.Constant.*;

/**
 * 订单
 * Created by 王念 on 2016/6/20.
 */
@RequestMapping("/v1/odr")
@RestController
public class OdrController {

    @Autowired
    private OdrService odrService;
    @Autowired
    private UsrService usrService;
    private static Logger logger = LoggerFactory.getLogger(OdrController.class);


    /**
     * 提交演出的订单
     *
     * @param type
     * @param token
     * @param addressId
     * @param performanceId
     * @param jsonBuyItem
     * @param orderPrice
     * @return
     */
    @ApiOperation(value = "(APP)提交演出的订单", notes = "返回参数: </br>成功: </br>{status: SUCCESS, </br>message: 提交成功, </br>data: {</br>&nbsp;&nbsp;orderSn: aaa(订单编号)</br>&nbsp;}</br>}" +
            "</br>重新登录: </br>{status: RELOGIN, message: Token失效}" +
            "</br>失败: </br>{status: FAILURE, message: 提交失败}")
    @RequestMapping(value = "/submitPerformaceOrder", method = RequestMethod.POST)
    public ResponseParameter submitPerformaceOrder(@ApiParam(value = "(必填)类型, APP", required = true) @RequestHeader String type,
                                                   @ApiParam(value = "(必填)用户token", required = true) @RequestHeader String token,
                                                   @ApiParam(value = "(必填)收货地址id", required = true) @RequestParam Integer addressId,
                                                   @ApiParam(value = "(必填)演出id", required = true) @RequestParam Integer performanceId,
                                                   @ApiParam(value = "(必填)购买项目JSON [{'number':1,'ticketId':2},{'number':2,'ticketId':5}]", required = true) @RequestParam String jsonBuyItem,
                                                   @ApiParam(value = "(必填)订单价格", required = true) @RequestParam String orderPrice) {
        logger.info("提交订单接口请求参数 type:{} ,token:{},addressId:{},performanceId：{}，jsonBuyItem:{},orderPrice:{}", type, token, addressId, performanceId, jsonBuyItem, orderPrice);
        ResponseParameter responseParameter = new ResponseParameter(Message.FAILURE, GET_FAILURE);
        Integer userId = usrService.getUserId(type, token, true);
        //将购买项目JSON转换成 lists
        List<OdrOrderItems> lists = new ArrayList<>();
        try {
            List<TicketBuyItem> lists1 = JSON.parseArray(jsonBuyItem, TicketBuyItem.class);
            for (TicketBuyItem ticketBuyItem : lists1) {
                OdrOrderItems odrOrderItems = new OdrOrderItems();
                odrOrderItems.setGoodsId(ticketBuyItem.getTicketId());
                odrOrderItems.setGoodsTotalCount(ticketBuyItem.getNumber());
                lists.add(odrOrderItems);
            }
        } catch (Exception ex) {
            logger.warn("传入的json错误=购买项目JSON:{}", jsonBuyItem);
            throw new CustomBizException(NO_ITEMS);
        }
        //创建订单
        String orderSn = odrService.createPreformaceOrder(userId, addressId, new BigDecimal(orderPrice), performanceId, lists);
        if (CommonValidator.isStringsNotNull(orderSn)) {
            Map<Object, Object> map = new HashMap<>();
            map.put("orderSn", orderSn);
            responseParameter.setStatus(Message.SUCCESS);
            responseParameter.setMessage(CREATE_ORDER_SUCCESS);
            responseParameter.setData(map);
        }
        logger.info("提交演唱会订单接口响应参数 :{}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    /**
     * 提交众筹订单接口
     *
     * @param type
     * @param token
     * @param addressId
     * @param jsonBuyItem
     * @param orderPrice
     * @return
     */
    @ApiOperation(value = "(APP)提交众筹订单接口", notes = "返回参数: </br>成功: </br>{status: SUCCESS, </br>message: 下单成功,</br>data:{</br>&nbsp;&nbsp;orderSn: 871473672159406(订单Sn)</br>&nbsp;}</br>}" +
            "</br>重新登录: </br>{status: RELOGIN, message: Token失效}" +
            "</br>失败: </br>{status: FAILURE, message: 参数不全}</br>{status: FAILURE, message: 下单失败}</br>{status: FAILURE, message: 没有商品}")
    @RequestMapping(value = "/submitOrder", method = RequestMethod.POST)
    public ResponseParameter submitOrder(@ApiParam(value = "(必填)类型, APP", required = true) @RequestHeader String type,
                                         @ApiParam(value = "(必填)用户token", required = true) @RequestHeader String token,
                                         @ApiParam(value = "(必填)收货地址id", required = true) @RequestParam Integer addressId,
                                         @ApiParam(value = "(必填)众筹id", required = true) @RequestParam Integer crowdfundingId,
                                         @ApiParam(value = "(必填)购买项目JSON [{'number':1,'payBackId':2},{'number':2,'payBackId':5}]", required = true) @RequestParam String jsonBuyItem,
                                         @ApiParam(value = "(必填)订单价格", required = true) @RequestParam String orderPrice) {
        logger.info("提交订单接口请求参数 type:{} ,token:{},addressId:{},crowdfundingId：{}，jsonBuyItem:{},orderPrice:{}", type, token, addressId, crowdfundingId, jsonBuyItem, orderPrice);
        ResponseParameter responseParameter = new ResponseParameter(Message.FAILURE, CREATE_ORDER_FAILURE);
        if (!CommonValidator.isStringsNotNull(type, token, addressId, jsonBuyItem, orderPrice)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        Integer userId = usrService.getUserId(type, token, true);
        //将购买项目JSON转换成 lists
        List<OdrOrderItems> lists = new ArrayList<>();
        try {
            List<PayBackBuyItem> lists1 = JSON.parseArray(jsonBuyItem, PayBackBuyItem.class);
            for (PayBackBuyItem buyItem : lists1) {
                OdrOrderItems odrOrderItems = new OdrOrderItems();
                odrOrderItems.setGoodsId(buyItem.getPayBackId());
                odrOrderItems.setGoodsTotalCount(buyItem.getNumber());
                lists.add(odrOrderItems);
            }
        } catch (Exception ex) {
            logger.warn("传入的json错误=购买项目JSON:{}", jsonBuyItem);
            throw new CustomBizException(NO_ITEMS);
        }
        //创建订单
        String orderSn = odrService.createOrder(userId, addressId, new BigDecimal(orderPrice), crowdfundingId, lists);
        if (CommonValidator.isStringsNotNull(orderSn)) {
            Map<Object, Object> map = new HashMap<>();
            map.put("orderSn", orderSn);
            responseParameter.setStatus(Message.SUCCESS);
            responseParameter.setMessage(CREATE_ORDER_SUCCESS);
            responseParameter.setData(map);
        }
        logger.info("提交订单接口响应参数 :{}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    /**
     * 我的订单列表
     *
     * @param type
     * @param token
     * @param type
     * @param token
     * @return
     */
    @ApiOperation(value = "(APP)获取我的订单", notes = "描述: </br>删除字段：</br>crowdfundingImage(众筹图片),statusEn(众筹状态),crowdfundingCity(众筹城市),crowdfundingTitle(众筹标题),statusZh(众筹状态)</br>修改字段: </br>crowdfundingId(众筹ID)&nbsp;&nbsp;改为&nbsp;&nbsp;businessId(商业ID)</br>添加字段: </br>orderImageUrl(订单图片地址), orderCity(订单城市), businessType(商业类型)</br>返回参数: </br>成功: </br>{status: SUCCESS, </br>message: 获取成功,</br>data:{</br>&nbsp;&nbsp;info:[" +
            "</br>&nbsp;&nbsp;&nbsp;{</br>&nbsp;&nbsp;&nbsp;&nbsp;orderStatusEn: INVALID(状态 APPLY：待支付,PAID：已支付，REFUND：退款, INVALID：过期),</br>&nbsp;&nbsp;&nbsp;&nbsp;sumPrice: 0.01(总价),</br>&nbsp;&nbsp;&nbsp;&nbsp;orderId: 1(订单Id),</br>&nbsp;&nbsp;&nbsp;&nbsp;orderSn: 147270602747894(订单SN),</br>&nbsp;&nbsp;&nbsp;&nbsp;businessId: 1(商业ID)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;orderStatus: 失效(状态 待支付/已支付/退款/过期)</br>&nbsp;&nbsp;&nbsp;&nbsp;orderImageUrl: http://swarm-dev.b0.upaiyun.com/cfi/app/cfi_app_florida.jpg (订单图片), </br>&nbsp;&nbsp;&nbsp;&nbsp;postage: 12(邮费), </br>&nbsp;&nbsp;&nbsp;&nbsp;orderTime: 1472706027000(下单时间), </br>&nbsp;&nbsp;&nbsp;&nbsp;sumPriceAndPostage: (价钱和邮费总数目),</br>&nbsp;&nbsp;&nbsp;&nbsp;orderCity：上海(订单城市),</br>&nbsp;&nbsp;&nbsp;&nbsp;payDetail： ￥0.01×1;(订单明细)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;businessType：CFI(商务类型(CROWDFUNDING,PERFORMANCE)),</br>&nbsp;&nbsp;&nbsp;&nbsp;orderTitle: 147270602747894(订单名),</br>&nbsp;&nbsp;&nbsp;&nbsp;beforeCloseTime:0(订单还有多久失效),</br>&nbsp;&nbsp;&nbsp;&nbsp;requestStatus: ALL(订单状态  APPLY：待支付  ALL: 全部订单(不包括待支付))</br>&nbsp;&nbsp;&nbsp;}</br>&nbsp;&nbsp;]</br>&nbsp;}</br>}" +
            "</br>重新登录: </br>{status: RELOGIN, message: Token失效}" +
            "</br>失败: </br>{status: FAILURE, message: 参数不全}")
    @RequestMapping(value = "/getOrderList/{page}/{count}/{orderStatus}", method = RequestMethod.GET)
    public ResponseParameter getOrderList(@ApiParam(value = "(必填)类型, APP", required = true) @RequestHeader String type,
                                          @ApiParam(value = "(必填)用户token", required = true) @RequestHeader String token,
                                          @ApiParam(value = "(必填)第几页", required = true) @PathVariable("page") Integer page,
                                          @ApiParam(value = "(必填)显示多少行", required = true) @PathVariable("count") Integer count,
                                          @ApiParam(value = "(必填)订单状态  APPLY：待支付  ALL: 全部订单（不包括待支付）  ", required = true) @PathVariable(value = "orderStatus") String orderStatus) {
        logger.info("我的订单接口请求参数 type:{} ,token:{},orderStatus:{},page:{},count:{}", type, token, orderStatus, page, count);
        ResponseParameter responseParameter = new ResponseParameter(Message.SUCCESS, GET_SUCCESS);
        if (!CommonValidator.isStringsNotNull(type, token)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        Integer userId = usrService.getUserId(type, token, true);
        List<Map<String, Object>> orderList = odrService.getOrderByUserIdAndStatus(userId, orderStatus, page, count);
        Map<Object, Object> map = new HashMap<>();
        map.put("info", orderList);
        responseParameter.setData(map);
        logger.debug("我的订单接口响应参数 :{}", JSON.toJSON(responseParameter));
        logger.info("我的订单接口响应参数 : 查询{}页，显示{}条,查询多少条:{}", page, count, orderList.size());
        return responseParameter;
    }

    /**
     * 我的订单
     *
     * @param type
     * @param token
     * @param type
     * @param token
     * @return
     */
    @ApiOperation(value = "(APP)订单详细", notes = "描述: </br>返回参数: </br>成功: </br>{status: SUCCESS, </br>message: 获取成功,</br>data:{</br>&nbsp;&nbsp;info:{</br>&nbsp;&nbsp;&nbsp;zipCode: 1111(邮编),</br>&nbsp;&nbsp;&nbsp;other: aaa(剩余地址),</br>&nbsp;&nbsp;&nbsp;sumPrice: 123(总价),</br>&nbsp;&nbsp;&nbsp;orderSn: 147262593260288(订单Sn),</br>&nbsp;&nbsp;&nbsp;payTime: 1472625913000(付款时间),</br>&nbsp;&nbsp;&nbsp;city: 北京市(众筹城市)," +
            "</br>&nbsp;&nbsp;&nbsp;businessId: 1(商业ID),</br>&nbsp;&nbsp;&nbsp;addressId: 1(地址ID),</br>&nbsp;&nbsp;&nbsp;orderImageUrl: http://aaa.png (订单图片地址),</br>&nbsp;&nbsp;&nbsp;orderTime: 1472625933000(订单创建时间),</br>&nbsp;&nbsp;&nbsp;province: 上海(省会),</br>&nbsp;&nbsp;&nbsp;road: aaa(道路),</br>&nbsp;&nbsp;&nbsp;sumPriceAndPostage: 200(邮费和物品总价)," +
            "</br>&nbsp;&nbsp;&nbsp;statusZh: (众筹状态 预热中/众筹中/已完成/失败),</br>&nbsp;&nbsp;&nbsp;orderTitle: 147262593260288(订单名称),</br>&nbsp;&nbsp;&nbsp;beforeCloseTime: 0(订单还有多久失效),</br>&nbsp;&nbsp;&nbsp;statusEn: PROCESS(众筹状态 PREPARE/PROCESS/COMPLETE/FAILURE),</br>&nbsp;&nbsp;&nbsp;address: aaa(收货地址),</br>&nbsp;&nbsp;&nbsp;mobile: 1111(收货人手机),</br>&nbsp;&nbsp;&nbsp;postage: 12(邮费)," +
            "</br>&nbsp;&nbsp;&nbsp;isDefault: 1(收货地址是否默认 1:是 0:否),</br>&nbsp;&nbsp;&nbsp;person: aaa(收货人),</br>&nbsp;&nbsp;&nbsp;district: aaa(区),</br>&nbsp;&nbsp;&nbsp;orderCity: 上海(订单城市),</br>&nbsp;&nbsp;&nbsp;payChannel: 支付宝(支付渠道名),</br>&nbsp;&nbsp;&nbsp;payDetail: ￥0.01×1;(付款详情),</br>&nbsp;&nbsp;&nbsp;businessType: CFI(商业类型 CROWDFUNDING,PERFORMANCE)</br>&nbsp;&nbsp;}</br>&nbsp;}</br>}" +
            "</br>重新登录: </br>{status: RELOGIN, message: Token失效}" +
            "</br>失败: </br>{status: FAILURE, message: 参数不全}")
    @RequestMapping(value = "/getOrderPaid/{orderSn}", method = RequestMethod.GET)
    public ResponseParameter getOrderPaid(@ApiParam(value = "(必填)类型, APP", required = true) @RequestHeader String type,
                                          @ApiParam(value = "(必填)用户token", required = true) @RequestHeader String token,
                                          @ApiParam(value = "(必填)订单号", required = true) @PathVariable(value = "orderSn") String orderSn) {
        logger.info("订单详细接口请求参数 type:{} ,token:{},orderSn:{}", type, token, orderSn);
        ResponseParameter responseParameter = new ResponseParameter(Message.SUCCESS, GET_SUCCESS);
        if (!CommonValidator.isStringsNotNull(type, token)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        Integer userId = usrService.getUserId(type, token, true);
        Map<String, Object> orderMap = odrService.getOrderByOrderSnAndUserId(orderSn, userId);
        Map<Object, Object> map = new HashMap<>();
        map.put("info", orderMap);
        responseParameter.setData(map);
        logger.info("订单详细接口响应参数 :{}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    /**
     * 删除订单
     *
     * @param type
     * @param token
     * @param type
     * @param token
     * @return
     */
    @ApiOperation(value = "(APP)删除订单", notes = "返回参数: </br>成功: </br>{status: SUCCESS, message: 删除成功}" +
            "</br>重新登录: </br>{status: RELOGIN, message: Token失效}" +
            "</br>失败: </br>{status: FAILURE, message: 参数不全}</br>{status: FAILURE, message: 删除失败}")
    @RequestMapping(value = "/delectOrder/{orderSn}", method = RequestMethod.DELETE)
    public ResponseParameter delectOrder(@ApiParam(value = "(必填)类型, APP", required = true) @RequestHeader String type,
                                         @ApiParam(value = "(必填)用户token", required = true) @RequestHeader String token,
                                         @ApiParam(value = "(必填)订单的orderSn", required = true) @PathVariable(value = "orderSn") String orderSn) {
        logger.info("删除订单接口请求参数 type:{} ,token:{},orderSn:{}", type, token, orderSn);
        ResponseParameter responseParameter = new ResponseParameter(Message.FAILURE, DELETE_FAILURE);
        if (!CommonValidator.isStringsNotNull(type, token, orderSn)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        Integer userId = usrService.getUserId(type, token, true);
        boolean bool = odrService.delectOrder(userId, orderSn);
        if (bool) {
            responseParameter.setStatus(Message.SUCCESS);
            responseParameter.setMessage(DELETE_SUCCESS);
        }
        logger.info("删除订单接口响应参数 :{}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    /**
     * 查询票务列表
     *
     * @param type
     * @param token
     * @param type
     * @param token
     * @return
     */
    @ApiOperation(value = "(APP)查询票务列表", notes = "返回参数: </br>成功: </br>{status: SUCCESS, </br>message: 获取成功,</br>data:{</br>&nbsp;&nbsp;info:[</br>&nbsp;&nbsp;&nbsp;{</br>&nbsp;&nbsp;&nbsp;&nbsp;ticketCreateTime: 1466739986000(创建日期),</br>&nbsp;&nbsp;&nbsp;&nbsp;image: http://aaa.png (图片),</br>&nbsp;&nbsp;&nbsp;&nbsp;address: 上海市漕溪北路1111号(地址),</br>&nbsp;&nbsp;&nbsp;&nbsp;fieldName: 上海人民广场(场地名字)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;ticketPrice: 500(票的价格),</br>&nbsp;&nbsp;&nbsp;&nbsp;businessId: 271(商业ID),</br>&nbsp;&nbsp;&nbsp;&nbsp;businessSn: aaa(商业Sn),</br>&nbsp;&nbsp;&nbsp;&nbsp;id: 1(票的ID),</br>&nbsp;&nbsp;&nbsp;&nbsp;concertName: 创创演唱会(演唱会名字),</br>&nbsp;&nbsp;&nbsp;&nbsp;businessType: CFI(商业类型 CROWDFUNDING,PERFORMANCE),</br>&nbsp;&nbsp;&nbsp;&nbsp;ticketName: 劳动人民票(票的名字),</br>&nbsp;&nbsp;&nbsp;&nbsp;status: USED(票的状态   VALID：有效，USED：已使用，EXPIRED：已过期)</br>&nbsp;&nbsp;&nbsp;}</br>&nbsp;&nbsp;]</br>&nbsp;}</br>}" +
            "</br>重新登录: </br>{status: RELOGIN, message: Token失效}" +
            "</br>失败: </br>{status: FAILURE, message: 参数不全}")
    @RequestMapping(value = "/getTicket/{page}/{count}", method = RequestMethod.GET)
    public ResponseParameter getTicket(@ApiParam(value = "(必填)类型, APP", required = true) @RequestHeader String type,
                                       @ApiParam(value = "(必填)用户token", required = true) @RequestHeader String token,
                                       @ApiParam(value = "(必填)第几页", required = true) @PathVariable("page") Integer page,
                                       @ApiParam(value = "(必填)显示多少行", required = true) @PathVariable("count") Integer count) {
        logger.info("查询票务列表请求参数 type:{} ,token:{}", type, token);
        ResponseParameter responseParameter = new ResponseParameter(Message.SUCCESS, GET_SUCCESS);
        if (!CommonValidator.isStringsNotNull(type, token)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        Integer userId = usrService.getUserId(type, token, true);
        List<Map<String, Object>> list = odrService.getTicketByUserId(userId, page, count);
        Map<Object, Object> map = new HashMap<>();
        map.put("info", list);
        responseParameter.setData(map);
        logger.info("查询票务列表响应参数 :{}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    /**
     * 查询单张票信息
     *
     * @param type
     * @param token
     * @param type
     * @param token
     * @return
     */
    @ApiOperation(value = "(APP)查询单张票信息", notes = "返回参数: </br>成功: </br>{status: SUCCESS, </br>message: 获取成功,</br>data:{</br>&nbsp;&nbsp;info:{</br>&nbsp;&nbsp;&nbsp;ticketCreateTime: 1466739986000(创建日期),</br>&nbsp;&nbsp;&nbsp;ticketValidCode: 1_0 (验票码),</br>&nbsp;&nbsp;&nbsp;&nbsp;address: 上海市漕溪北路1111号(地址),</br>&nbsp;&nbsp;&nbsp;&nbsp;fieldName: 上海人民广场(场地名字)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;ticketPrice: 500(票的价格),</br>&nbsp;&nbsp;&nbsp;&nbsp;latitude: 31.187854(纬度),</br>&nbsp;&nbsp;&nbsp;&nbsp;ticketType: DIGITAL(验票码类型 DIGITAL：电子票，ENTIITY：实体票),</br>&nbsp;&nbsp;&nbsp;&nbsp;concertName: 创创演唱会(演唱会名字),</br>&nbsp;&nbsp;&nbsp;&nbsp;seatInfo: A区12排5座(座位信息),</br>&nbsp;&nbsp;&nbsp;&nbsp;ticketName: 劳动人民票(票的名字)," +
            "</br>&nbsp;&nbsp;&nbsp;&nbsp;longitude: 121.444761(经度),</br>&nbsp;&nbsp;&nbsp;&nbsp;status: USED(票的状态   VALID：有效，USED：已使用，EXPIRED：已过期)</br>&nbsp;&nbsp;&nbsp;}</br>&nbsp;&nbsp;]</br>&nbsp;}</br>}" +
            "</br>重新登录: </br>{status: RELOGIN, message: Token失效}" +
            "</br>失败: </br>{status: FAILURE, message: 参数不全}</br>{status: FAILURE, message: 获取失败}")
    @RequestMapping(value = "/getTicket/{ticketId}", method = RequestMethod.GET)
    public ResponseParameter getTicke(@ApiParam(value = "(必填)类型, APP", required = true) @RequestHeader String type,
                                      @ApiParam(value = "(必填)用户token", required = true) @RequestHeader String token,
                                      @ApiParam(value = "(必填)票的Id", required = true) @PathVariable("ticketId") Integer ticketId) {
        logger.info("查询单张票信息接口请求参数 type:{} ,token:{},ticketId:{}", type, token, ticketId);
        ResponseParameter responseParameter = new ResponseParameter(Message.FAILURE, GET_FAILURE);
        if (!CommonValidator.isStringsNotNull(type, token)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        Integer userId = usrService.getUserId(type, token, true);
        Map<String, Object> resultMap = odrService.getTicketById(userId, ticketId);
        if (resultMap != null) {
            responseParameter.setMessage(GET_SUCCESS);
            responseParameter.setStatus(Message.SUCCESS);
            Map<Object, Object> map = new HashMap<>();
            map.put("info", resultMap);
            responseParameter.setData(map);
        }
        logger.info("查询单张票信息接口响应参数 :{}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

//    /**
//     * 获取二维码.
//     *
//     * @param type
//     * @param token
//     * @param type
//     * @param token
//     * @return
//     */
//    @ApiOperation(value = "获取二维码(APP)", notes = "APP 必填字段 type token ticketId")
//    @RequestMapping(value = "/getQrCode/{ticketId}", method = RequestMethod.GET)
//    public ResponseParameter getQrCode(@ApiParam(value = "APP或者WEB", required = true) @RequestHeader String type,
//                                       @ApiParam(value = "用户token", required = true) @RequestHeader String token,
//                                       @ApiParam(value = "票的Id", required = true) @PathVariable("ticketId") Integer ticketId) {
//        logger.info("获取二维码接口请求参数 type:{} ,token:{},ticketId:{}", type, token, ticketId);
//        ResponseParameter responseParameter = new ResponseParameter(Message.FAILURE, GET_FAILURE);
//        if (!CommonValidator.isStringsNotNull(type, token, ticketId)) {
//            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
//        }
//        Integer userId = usrService.getUserId(type, token, true);
//        String qrcodeStr = odrService.getQrcode(userId, ticketId);
//        if (qrcodeStr != null) {
//            responseParameter.setMessage(GET_SUCCESS);
//            responseParameter.setStatus(Message.SUCCESS);
//            Map<Object, Object> map = new HashMap<>();
//            map.put("info", qrcodeStr);
//            responseParameter.setData(map);
//        }
//        logger.info("获取二维码响应参数 :{}", JSON.toJSON(responseParameter));
//        return responseParameter;
//    }

    /**
     * 验证二维码
     *
     * @return
     */
    @ApiOperation(value = "(APP)验证二维码", notes = "返回参数:</br>成功:</br>{status: SUCCESS, message: 验证通过}" +
            "</br>失败: </br>{status: FAILURE, message: 参数不全}</br>{status: FAILURE, message: 二维码无效}</br>{status: FAILURE, message: 验票员身份无效}" +
            "</br>{status: FAILURE, message: 尚未开启验证}")
    @RequestMapping(value = "/checkQrCode", method = RequestMethod.POST)
    public ResponseParameter checkQrCode(@ApiParam(value = "(必填)验票员Sn", required = true) @RequestHeader String inspectorSn,
                                         @ApiParam(value = "(必填)二维码", required = true) @RequestParam String Qrcode) {
        logger.info("验证二维码接口请求参数 inspectorSn:{} ,Qrcode:{}", inspectorSn, Qrcode);
        ResponseParameter responseParameter = new ResponseParameter(Message.SUCCESS, QRCODE_VALID);
        if (!CommonValidator.isStringsNotNull(inspectorSn, Qrcode)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        Boolean bool = odrService.checkQrcode(inspectorSn, Qrcode);
        if (!bool) {
            responseParameter = new ResponseParameter(Message.FAILURE, QRCODE_INVALID);
        }
        logger.info("验证二维码 响应参数 :{}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    /**
     * 扫描二维码
     *
     * @return
     */
    @ApiOperation(value = "(APP)扫描二维码", notes = "返回参数: </br>成功: </br>{status: SUCCESS, message: 验证通过}" +
            "</br>重新登录: </br>{status: RELOGIN, message: Token失效}" +
            "</br>失败: </br>{status: FAILURE, message: 参数不全}</br>{status: FAILURE, message: 二维码无效}</br>{status: FAILURE, message: 验证失败}</br>{status: FAILURE, message: 已过期/已使用}</br>{status: FAILURE, message: 尚未开启验证}")
    @RequestMapping(value = "/scanQrcode", method = RequestMethod.POST)
    public ResponseParameter scanQrcode(@ApiParam(value = "(必填)类型, APP", required = true) @RequestHeader String type,
                                        @ApiParam(value = "(必填)用户token", required = true) @RequestHeader String token,
                                        @ApiParam(value = "(必填)二维码", required = true) @RequestParam String Qrcode,
                                        @ApiParam(value = "(必填)票的Id", required = true) @RequestParam Integer ticketId) {
        logger.info("扫描二维码接口请求参数 type:{} ,token:{},Qrcode:{},ticketId:{}", type, token, Qrcode, ticketId);
        ResponseParameter responseParameter = new ResponseParameter(Message.SUCCESS, QRCODE_VALID);
        if (!CommonValidator.isStringsNotNull(type, token, ticketId, Qrcode)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        Integer userId = usrService.getUserId(type, token, true);
        Boolean bool = odrService.scanQrcode(Qrcode, userId, ticketId);
        if (!bool) {
            responseParameter = new ResponseParameter(Message.FAILURE, QRCODE_INVALID);
        }
        logger.info("扫描二维码 响应参数 :{}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    /**
     * 支付宝支付信息
     *
     * @param type
     * @param token
     * @param type
     * @param token
     * @return
     */
    @ApiOperation(value = "(APP)获取支付信息", notes = "返回参数: </br>成功: </br>{status: SUCCESS, </br>message: 获取成功,</br>data:{</br>&nbsp;&nbsp;orderDescribe: 蜂超音乐(订单描述),</br>&nbsp;&nbsp;alipayNotifyUrl: http://139.196.210.221:8085/pay/alipay/asynchronousNotify (回调地址)</br>&nbsp;&nbsp;orderPrice: 10(订单价格),</br>&nbsp;&nbsp;RsaPrivate: aaa(私钥),</br>&nbsp;&nbsp;orderName: 上海蜂超文化传播有限公司(订单名称)</br>&nbsp;}</br>}" +
            "</br>重新登录: </br>{status: RELOGIN, message: Token失效}" +
            "</br>失败: </br>{status: FAILURE, message: 参数不全}</br>{status: FAILURE, message: 非法的请求}</br>{status: FAILURE, message: 订单已失效}")
    @RequestMapping(value = "/getPayInfo/{payType}/{orderSn}", method = RequestMethod.GET)
    public ResponseParameter getPayInfo(@ApiParam(value = "(必填)类型, APP", required = true) @RequestHeader String type,
                                        @ApiParam(value = "(必填)用户token", required = true) @RequestHeader String token,
                                        @ApiParam(value = "(必填)支付方式（ALIPAY,WEIXIN）", required = true) @PathVariable("payType") String payType,
                                        @ApiParam(value = "(必填)订单号", required = true) @PathVariable("orderSn") String orderSn) {
        logger.info("获取支付信息接口请求参数 type:{} ,token:{},payType:{}，orderSn：{}", type, token, payType, orderSn);
        ResponseParameter responseParameter = new ResponseParameter(Message.SUCCESS, GET_SUCCESS);
        if (!CommonValidator.isStringsNotNull(type, token)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        Integer userId = usrService.getUserId(type, token, true);
        OdrOrder odrOrder = odrService.getOdrOrder(orderSn, userId);
        logger.debug("odrOrder:{}", JSON.toJSON(odrOrder));
        if (odrOrder == null) {
            throw new CustomBizException(ILLEGAL_REQUEST);
        }
        //如果过期时间等于或者小于当前时间 订单过期
        Date nowDate = new Date();
        if (DateUtil.computeTimestamp(odrOrder.getOrderExpireTime(), nowDate) == 0) {
            throw new CustomBizException(ORDER_INVALID);
        }
        Map<Object, Object> map = new HashMap<>();
        if ("ALIPAY".equals(payType)) {
            map.put("orderPrice", odrOrder.getOrderPrice());
            map.put("orderDescribe", ORDER_DESCRIBE);
            map.put("orderName", ORDER_NAME);
            map.put("RsaPrivate", RSA_PRIVATE);
            map.put("alipayNotifyUrl", CONFIGMAP.get("alipay.asynchronousNotifyUrl"));
        }
        if ("WEIXIN".equals(payType)) {
        }
        responseParameter.setData(map);
        logger.info("获取支付信息接口响应参数 :{}", JSON.toJSON(responseParameter));
        return responseParameter;
    }

    /**
     * 微信支付统一下单
     *
     * @param type
     * @param token
     * @param type
     * @param token
     * @return
     */
    @ApiOperation(value = "(APP)微信支付统一下单", notes = "返回参数: </br>成功: </br>{status: SUCCESS, </br>message: 获取成功,</br>data:{</br>&nbsp;&nbsp;package: Sign=WXPay,</br>&nbsp;&nbsp;appid: wx10d42e46ab5fd35b,</br>&nbsp;&nbsp;sign: CCE920395B00F129447895E6D9BE51BA," +
            "</br>&nbsp;&nbsp;partnerid: 1370249302,</br>&nbsp;&nbsp;prepayid: wx20160912172255fd09ae57a50046298270,</br>&nbsp;&nbsp;noncestr: 1473672175693,</br>&nbsp;&nbsp;timestamp: 1473672175</br>&nbsp;}</br>}" +
            "</br>重新登录: </br>{status: RELOGIN, message: Token失效}" +
            "</br>失败: </br>{status: FAILURE, message: 参数不全}</br>{status: FAILURE, message: 获取失败}</br>{status: FAILURE, message: 非法的请求}</br>{status: FAILURE, message: 订单已失效}")
    @RequestMapping(value = "/unifiedOrder/{orderSn}", method = RequestMethod.GET)
    public ResponseParameter unifiedOrder(HttpServletRequest httpServletRequest,
                                          @ApiParam(value = "(必填)类型, APP", required = true) @RequestHeader String type,
                                          @ApiParam(value = "(必填)用户token", required = true) @RequestHeader String token,
                                          @ApiParam(value = "(必填)订单号", required = true) @PathVariable("orderSn") String orderSn) {
        logger.info("微信支付统一下单请求参数 type:{} ,token:{},orderSn:{}", type, token, orderSn);
        ResponseParameter responseParameter = new ResponseParameter(Message.FAILURE, GET_FAILURE);
        if (!CommonValidator.isStringsNotNull(type, token, orderSn)) {
            throw new CustomBizException(PARAMETER_IS_NOT_COMPLETE);
        }
        Integer userId = usrService.getUserId(type, token, true);
        OdrOrder odrOrder = odrService.getOdrOrder(orderSn, userId);
        if (odrOrder == null) {
            throw new CustomBizException(ILLEGAL_REQUEST);
        }
        //如果过期时间等于或者小于当前时间 订单过期
        Date nowDate = new Date();
        if (DateUtil.computeTimestamp(odrOrder.getOrderExpireTime(), nowDate) == 0) {
            throw new CustomBizException(ORDER_INVALID);
        }
        BigDecimal orderPrice = odrOrder.getOrderPrice();
        Integer centPrivce = orderPrice.multiply(new BigDecimal(100)).intValue();
        Map<Object, Object> requstMap = WeixinPay.sendWxPayRequest(orderSn, centPrivce.toString(), IpUtil.getLocalIp(httpServletRequest));
        if (requstMap != null) {//如果下单成功
            responseParameter.setMessage(GET_SUCCESS);
            responseParameter.setStatus(Message.SUCCESS);
            responseParameter.setData(requstMap);
        }
        logger.info("微信支付统一下单响应参数 :{}", JSON.toJSON(responseParameter));
        return responseParameter;
    }


}
